<?php


header("Content-type:text/html;charset=utf-8");
$id = $_GET['id'];


//链接数据库
$server = 'localhost';
$user = 'root';
$psw = 'root';
$db = 'qq';

try{

	if(!isset($_POST)) exit;
	$conn = new PDO("mysql:host=$server;dbname=$db",$user,$psw);
	$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

	//把数据写入数据库保存
	session_start();
	$fid = $_SESSION['id'];  
	$tid = $_GET['id'];
	$addtime = time();
	//a对b聊天,插入一条聊天记录
	$sql = "insert into talk values (NULL,'$fid','$tid','$_POST[content]','$addtime','1')";
	
	$conn->exec($sql);

	header("Location:talk.php?id=$id");
}catch(PDOException $e){
    echo $sql . "<br>" . $e->getMessage();
}



